<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	request.setAttribute("path", request.getContextPath());
%>
<!DOCTYPE html>
<html>
<head>
	<title>致-青春   ${userInfo.usr }的主页</title>
	<link rel="stylesheet" type="text/css" href="${path}/css/base.css" />
	<script type="text/javascript" src="${path}/js/jquery-1.10.2.min.js"></script>
	<script type="text/javascript">
		function notice(id) {
			var myId = '${sessionScope.user.id }';
			if (myId == "") {
				alert("请先登录");
				return;
			}
			$.post("${path}/noticeUser.html", 
					{
						id : id,
						myId : myId
					},
					function(data) {
						if (data == "true") {
							$("#cancel_button").show();
							$("#contact_button").hide();
						}
					});
		}
		
		function cancel(id) {
			var myId = '${sessionScope.user.id }';
			$.post("${path}/cancelNoticeUser.html", 
					{
						id : id,
						myId : myId
					},
					function(data) {
						if (data == "true") {
							$("#cancel_button").hide();
							$("#contact_button").show();
						}
					});
		}
		
		$(function(){
			var isContact = "${isContact}";
			if (isContact == "true") {
				$("#cancel_button").show();
				$("#contact_button").hide();
			} 
		});
				
		function newArticle() {
			location = "userNewArticle.html";
		}
		
		function mail(id) {
			location = "newbox.html?id=" + id;
		}
		
		function setup() {
			location = "userInfo.html";
		}
	</script>
</head>
<body>
	<div id="container">
		<jsp:include page="/page/common/header.jsp"></jsp:include>
		<div id="kernel" class="center-box">
			<div class="user-zone">
				<div class="user-info">
					<div class="user-head">
						<span>
							个人资料	
						</span>
					</div>
					<div class="user-self">
						<img alt="user-avatar" src="${path }/img/avatar/${userInfo.avatar }">
						<ul>
							<li>
								<label>用户名:</label>
								<b>${userInfo.usr }</b>
							</li>
							<li>
								<label>邮箱地址:</label>
								<b>${userInfo.email }</b>
							</li>
							<li>
								<label>注册时间:</label>
								<b><fmt:formatDate value="${userInfo.dt }" pattern="yyyy-MM-dd"/></b>
							</li>
						</ul>
						<div class="user-relate">
<%-- 
							// 暂时不开启关注和发私信功能（140109）
							<c:if test="${userInfo.id != sessionScope.user.id }">
							<input type="button" value="发消息" onclick="mail('${userInfo.id}')" />
							
							<input type="button" value="关注" onclick="notice('${userInfo.id}')" id="contact_button"/>
							<span id="cancel_button" style="display: none; "><a href="javascript:;" onclick="cancel('${userInfo.id}')">取消关注</a></span>
							</c:if>
 --%>							
 							<c:if test="${userInfo.id == sessionScope.user.id }">
								<input type="button" value="设置" onclick="setup();" />
							
								<input type="button" value="发表新文章" onclick="newArticle();" />
							</c:if>
						</div>
					</div>
				</div>
				
				<div class="user-article">
					<div class="user-head">
						<span>他的文章</span>
						<a href="userArticle.html?id=${userInfo.id }">更多</a>
					</div>
					<div class="category">
					<ul>
					<c:forEach items="${articleList }" var="item">
						<li>
							<div class="achievement">
		 						${item.total }
		 					</div>
							<div class="title">
								<a href="article.html?id=${item.id }">${item.title }</a>
							</div>
							<div class="summary">
								<span>${item.authorName }  发表于
									<fmt:formatDate value="${item.insertTime }" pattern="yyyy-MM-dd HH:mm:ss"/> 
								</span>
							</div>
						</li>
					</c:forEach>
					</ul>
					</div>
				</div>
				
 				<div class="user-zone-comment">
					<div class="user-head">
						<span>他的评论</span>
						<a href="userComment.html?id=${userInfo.id }">更多</a>
					</div>
					<div class="category">
					<ul>
					<c:forEach items="${commentList }" var="comment">
						<li>
							<p class="user-zone-comment-content">${comment.content }</p>
							<p class="user-zone-comment-info">
								<fmt:formatDate value="${comment.time }" pattern="yyyy-MM-dd HH:mm:ss"/>
								在
								<a href="article.html?id=${comment.articleId }">
									${comment.articleDO.title }
								</a>
							</p>
						</li>
					</c:forEach>
					</ul>
					</div>
				</div>
				
			</div>
			<div class="sidebar">
				<jsp:include page="/sidebar.html"></jsp:include>
			</div>
		</div>
		<jsp:include page="/page/common/footer.jsp"></jsp:include>
	</div>
</body>
</html>